<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        添加库房
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../../css/main.css" media="all">
    <script type="text/javascript" src="../../../../lib/loading/okLoading.js"></script>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="../../../../lib/layui/css/layui_2.5.7.css">

</head>
<style>
</style>

<body>
<div class="x-nav">
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon"
                                                                        style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body" id="app">
    <form class="layui-form layui-form-pane" id="add">
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <div class="layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>库房名称</label>
                    <div style="width: 72%" class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="warehouseName" v-model="warehouse.warehouseName"
                               lay-verify="required" placeholder="库房名称" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>库房位置</label>
                    <div style="width: 72%" class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="warehouseAddress" v-model="warehouse.warehouseAddress"
                               placeholder="库房位置" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>负责人员</label>
                    <div style="width: 72%" class="layui-input-inline">
                        <select name="dutyerId" lay-verify="required" lay-search="">
                            <option value="">---</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">备注信息</label>
                    <div style="width: 70%" class="layui-input-inline">
                         <textarea name="warehouseRemark" v-model="warehouse.warehouseRemark" placeholder="请输入内容"
                                   class="layui-textarea"></textarea>
                    </div>
                </div>

                <div style="text-align: center" class="layui-form-item">
                    <button class="layui-btn" type="button" lay-filter="sub" lay-submit="sub">
                        保存
                    </button>
                </div>
                <div style="height:20px;"></div>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript" src="../../../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../../../js/myAjax.js"></script>
<script type="text/javascript" src="../../../../js/pub.js"></script>
<script src="../../../../lib/layui/layui2.5.7.js" charset="utf-8"></script>
<script src="../../../../js/x-layui.js" charset="utf-8"></script>
<script src="../../../../js/vue.min.js" charset="utf-8"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>

<script>
    layui.use(['element', 'layer', 'form', 'laydate'], function () {
        $ = layui.jquery;//jquery
        lement = layui.element();//面包导航
        layer = layui.layer;//弹出层
        laydate = layui.laydate;//日期插件
        form = layui.form;
        okLoading.close($);
    })
</script>
<script>

    var recordId = getQueryVariable('recordId');
    var vm = new Vue({
        el: "#app",
        data: {
            warehouse: {
                id: null,
                warehouseName: null,
                warehouseAddress: null,
                warehouseRemark: null,
                dutyerId: null,
            }
        },
        created() {
            if (recordId) {
                let request1 = {
                    url: '/kf/warehouse/getWarehouseById',
                    data: {
                        userId: $userId,
                        warehouseId: recordId
                    },
                    method: "get",
                };
                sendRequest(request1, (res) => {
                    console.log(res);
                    this.warehouse = res.data;
                });
            }

        },
    })

    layui.use(['laydate', 'form', 'layer'],
        function () {
            var form = layui.form;
            var layer = layui.layer;

            //监听审批提交
            form.on('submit(sub)',
                function (data) {
                    let form = data.field;
                    form.userId = $userId;
                    form.id = vm.warehouse.id;
                    form.operationType = vm.warehouse.id == null ? 'add' : 'edit';
                    let request = {
                        url: 'kf/warehouse/addWarehouse',
                        data: form,
                        method: "post",
                    };
                    sendRequest(request, (data) => {
                        console.log(data);
                        if (data.code === 0) {
                            layer.alert("操作成功", {
                                    icon: 6
                                },
                                function () {
                                    var index = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index);
                                    parent.reload();
                                });
                        } else {
                            layer.alert(data.msg, {
                                icon: 5
                            })
                        }
                    });
                    return false;
                });

        });


    setTimeout(() => {
        let form = layui.form;
        let request = {
            url: 'user/findUserSelect',
            data: {
                userId: $userId,
            },
            method: "get",
        };
        sendRequest(request, (res) => {
            let d = res.data;
            $.each(d, function (index, item) {
                let opt = $("<option value=" + item.id + ">" + item.nickname + "</option>");
                $("select[name=dutyerId]").append(opt);
            });
            $("select[name=dutyerId]").val(vm.warehouse.dutyerId);

            form.render('select');
        });

    }, 300)

</script>

</body>

</html>
